﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZLB_Model.TiJian;

namespace ZLB_Dal.Basic
{
    public abstract class PhysicalSixDal : PhysicalDal
    {
        public override List<TiJianB> GetTiJianBList()
        {
            string sql = $@"SELECT 
tjb.TiJianH AS TiJianLSH,
tjb.TiJianH AS TiJianH,
tjb.ShenFenZhengH AS ShenFenZhengH,
tjb.ShouJiH AS ShouJiH,
tjb.XingMing AS XingMing,
tjb.XingBie AS XingBie,
CAST(tjb.NianLing AS VARCHAR) AS NianLing,
CONVERT(VARCHAR(100),ISNULL(tjb.DengJiRQ, GETDATE()) ,120)  AS DengJiRQ,
CONVERT(VARCHAR(100),ISNULL(tjb.ZongJianRQ, GETDATE()) ,120)  AS ZongJianRQ,
CONVERT(VARCHAR(100),ISNULL(tjb.TiJianRQ, GETDATE()) ,120)  AS TiJianRQ
 FROM TiJianB AS tjb
LEFT JOIN ZLB_ReportUpload AS zlb
ON tjb.TiJianH=zlb.physical_serial_no
WHERE tjb.Status>3 AND tjb.ShangChuBZ='否' AND ISNULL(tjb.ShenFenZhengH, '')>'' 
AND zlb.physical_serial_no is NULL";

            return base.sqlHelper.GetData<TiJianB>(sql,System.Data.CommandType.Text);
        }

        public override TiJianB GetTiJianB(string tjh)
        {
            string sql = $@"SELECT 
tjb.TiJianH AS TiJianLSH,
tjb.TiJianH AS TiJianH,
tjb.ShenFenZhengH AS ShenFenZhengH,
tjb.ShouJiH AS ShouJiH,
tjb.XingMing AS XingMing,
tjb.XingBie AS XingBie,
CAST(tjb.NianLing AS VARCHAR) AS NianLing,
CONVERT(VARCHAR(100),ISNULL(tjb.DengJiRQ, GETDATE()) ,120)  AS DengJiRQ,
CONVERT(VARCHAR(100),ISNULL(tjb.ZongJianRQ, GETDATE()) ,120)  AS ZongJianRQ,
CONVERT(VARCHAR(100),ISNULL(tjb.TiJianRQ, GETDATE()) ,120)  AS TiJianRQ
 FROM TiJianB AS tjb
WHERE tjb.TiJianH='{tjh}'";

           List<TiJianB> listTJB = base.sqlHelper.GetData<TiJianB>(sql, System.Data.CommandType.Text).ToList();
            TiJianB tjb = null;
            if (listTJB != null && listTJB.Count > 0)
                tjb = listTJB[0];

            return tjb;
        }
    }
}
